﻿using System.Collections.Generic;
using UnityEngine;

namespace E.Story
{
    /// <summary>
    /// 故事数据
    /// </summary>
    public class StoryDataSO : ScriptableObject
    {
        [SerializeField] private string fileName;
        [SerializeField] private List<GroupData> groupDatas;
        [SerializeField] private List<NodeData> nodeDatas;
        [SerializeField] private List<VarData> varDatas;
        [SerializeField] private List<NoteData> stickyNoteDatas;

        #region 属性

        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName { get => fileName; set => fileName = value; }

        /// <summary>
        /// 分组数据列表
        /// </summary>
        public List<GroupData> GroupDatas { get => groupDatas; set => groupDatas = value; }

        /// <summary>
        /// 节点数据列表
        /// </summary>
        public List<NodeData> NodeDatas { get => nodeDatas; set => nodeDatas = value; }

        /// <summary>
        /// 变量数据列表
        /// </summary>
        public List<VarData> VarDatas { get => varDatas; set => varDatas = value; }

        /// <summary>
        /// 便签数据列表
        /// </summary>
        public List<NoteData> NoteDatas { get => stickyNoteDatas; set => stickyNoteDatas = value; }

        #endregion


        #region 方法

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="fileName"></param>
        public void Init(string fileName)
        {
            this.fileName = fileName;
            groupDatas = new();
            nodeDatas = new();
            varDatas = new();
            stickyNoteDatas = new();
        }

        /// <summary>
        /// 获取开始节点
        /// </summary>
        /// <returns>节点</returns>
        public NodeData GetStartNode()
        {
            foreach (NodeData nodeData in nodeDatas)
            {
                if (nodeData.Type == NodeType.Start)
                {
                    return nodeData;
                }
            }
            return null;
        }

        /// <summary>
        /// 获取节点
        /// </summary>
        /// <param name="nodeID">节点GUIID</param>
        /// <returns>节点</returns>
        public NodeData GetNode(string nodeID)
        {
            foreach (NodeData nodeData in nodeDatas)
            {
                if (nodeData.GUID == nodeID)
                {
                    return nodeData;
                }
            }
            return null;
        }

        #endregion
    }
}